﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IPC.Communication.Framework.Core.Address;
using IPC.Communication.Framework.Profinet.Melsec;

namespace IPC.Communication.Framework.Profinet.Panasonic
{
    public class PanasonicMcNet : MelsecMcNet
    {
        public PanasonicMcNet()
        {
        }

        public PanasonicMcNet(string ipAddress, int port)
            : base(ipAddress, port)
        {
        }

        public override OperateResult<McAddressData> McAnalysisAddress(string address, ushort length)
        {
            return McAddressData.ParsePanasonicFrom(address, length);
        }

        protected override OperateResult<byte[]> UnpackResponseContent(byte[] send, byte[] response)
        {
            ushort num = BitConverter.ToUInt16(response, 9);
            if (num != 0)
            {
                return new OperateResult<byte[]>(num, PanasonicHelper.GetMcErrorDescription(num));
            }
            return OperateResult.CreateSuccessResult(response.RemoveBegin(11));
        }

        public override string ToString()
        {
            return String.Format("PanasonicMcNet[{0}:{1}]", IpAddress, Port);
        }
    }
}